package com.chenjt.netty.six_gPRC.streamResponse;

import com.chenjt.netty.six_gPRC.generateCode.*;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

import java.util.Iterator;

/**
 * gRPC客户端
 *
 * 参考D:\programmer\studyWorkspace\netty\doc\grpc-java\examples\src\main\java\io\grpc\examples\helloworld\HelloWorldClient.java
 * @author chenjt
 * @date 2024/8/16 10:36
 */
public class GrpcClient {

    public static void main(String[] args) {
        ManagedChannel managedChannel = ManagedChannelBuilder.forAddress("localhost", 8899)
//                .usePlaintext(true)
                .usePlaintext()
                .build();

        StudentServiceGrpc.StudentServiceBlockingStub blockingStub
                = StudentServiceGrpc.newBlockingStub(managedChannel);

        Iterator<StudentResponse> iter = blockingStub
                .getStudentsByAge(StudentRequest.newBuilder().setAge(20).build());
        while(iter.hasNext()){
            StudentResponse studentResponse = iter.next();
            System.out.println(studentResponse.getName() + "," + studentResponse.getAge() + "," + studentResponse.getCity());
            System.out.println("--------");
        }


    }



}
